package com.cx330;

public class Example83_01 {
    public static void main(String[] args) throws InterruptedException {
        Thread worker = new Thread(() -> {
            while (true) {
                if (!Thread.currentThread().isInterrupted()) {
                    System.out.println("Worker thread is running");
                } else {
                    System.out.println("Worker clear ...");
                    break;
                }
            }
            System.out.println("Worker thread is exiting");
        });
        worker.start();
        // 主线程等待一段时间后中断工作线程
        Thread.sleep(1);
        worker.interrupt();
    }
}
